﻿@inherits MasaComponentBase

<MHover Context="hoverContext" Class="d-flex flex-column">
    <MCard Ripple=false OnClick="OnClick" Outlined MinHeight="Height" @attributes="hoverContext.Attrs" Class="appcard" Elevation="@(hoverContext.Hover ? 6 : 0)" Style="@Style">
        <MCardTitle Style="font-size: medium; flex-wrap:nowrap;" Class="pt-3 pb-2">
            <div class="emphasis2--text h7 text-overflow appname">@App.Name</div>
            <div class="mx-3" style="color:#E2E7F4">|</div>
            <div class="emphasis2--text h7 text-overflow">@App.Type</div>
            <MSpacer />
            <SButton OnClickStopPropagation Icon OnClick="OnPinClick">
                <SIcon Color="@(IsPin ? "#FFB547" : "#E5E5E5")" Size="20" Tooltip="@(IsPin ? T("Cancel Pin") : null)">mdi-pin</SIcon>
            </SButton>
        </MCardTitle>
        <MCardSubtitle>
        <div class="body2 regular3--text text-overflow">@App.Identity</div>
        </MCardSubtitle>
        <MCardText Class="px-4">
            <div class="text-overflow regular--text body text-overflow mb-4" style="min-height:24px;">@App.Description</div>
            <div class="full-width" @onclick:stopPropagation="true">
                @ChildContent
            </div>
            <LatestConfigPublish LatestReleaseConfigModel="LatestReleaseConfig" TextClass="regular3--text body3" TitleClass="regular3--text body3"></LatestConfigPublish>
        </MCardText>
    </MCard>
</MHover>

@code {
    [Parameter]
    public EventCallback<MouseEventArgs> OnClick { get; set; }

    [Parameter]
    public List<EnvironmentClusterModel> EnvironmentClusters { get; set; } = new();

    [Parameter]
    public LatestReleaseConfigModel? LatestReleaseConfig { get; set; } = null;

    [Parameter]
    public Model.AppModel App { get; set; } = new();

    [Parameter]
    public string EditInfo { get; set; } = "";

    [Parameter]
    public EventCallback<MouseEventArgs> OnPinClick { get; set; }

    [Parameter]
    public RenderFragment ChildContent { get; set; } = default!;

    [Parameter]
    public bool IsPin { get; set; }

    public int Height => 186;

    private async Task HandleOnClickAsync()
    {
        if (OnClick.HasDelegate)
        {
            await OnClick.InvokeAsync();
        }
    }
}
